home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_09_05
/
9n05102b
< prev
next >
Wrap
Text File
|
1991-03-19
|
956b
|
38 lines
// This function converts true to eccentric anomaly
// or vice versa.
// Input: x -- true or eccen anomaly
// i -- 1 means input is eccen anom
// 2 means input is true anom
// Output: the function returns eccen or true anom
// * Inputs/outputs are in degrees *
double enu(double x, double e, int i)
{
double cosy,y;
if (i) {
// Convert eccen to true anomaly
cosy = (e - cos(x))/(e*cos(x) - 1);
} else {
// Convert true to eccen anomaly
cosy = (e + cos(x))/(1+e*cos(x));
}
y = acos(cosy); // y is 0 to pi
if (x > PI)
y = TWOPI - y;
return(y);
}
SAMPLE INPUT/OUTPUT (very circular orbit)
Run 1 inputs: output:
x = 302.424192 (eccen anom) true anom = 302.420917
e = 0.000068
i = 1
Run 2 inputs: output:
x = 302.420917 (true anom) eccen anom = 302.424192
e = 0.000068
i = 0